package com.weishi.base;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;

public class dateConverter implements Converter<String, Date>{

	@Override
	public Date convert(String arg0) {
		
		
		try {
			SimpleDateFormat simpleDateFormate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			return simpleDateFormate.parse(arg0);
		} catch (ParseException e) {
			SimpleDateFormat simpleDateFormate = new SimpleDateFormat("yyyy-MM-dd");
			try {
				return simpleDateFormate.parse(arg0);
			} catch (ParseException e1) {
				//e1.printStackTrace();
				throw new RuntimeException("将 "+arg0+" 转换成日期转换失败,日期格式:yyyy-MM-dd");
			}
			
			
		}
	}

}
